package com.gc.server.controller.api;

import com.gc.server.entity.BusApplyEntity;
import com.gc.server.entity.ImgOrderEntity;
import com.gc.server.service.*;
import com.gc.server.vo.ImgOrderStatusEnum;
import com.gc.server.vo.ImgOrderVo;
import com.yf.annotation.LoginUserId;
import com.yf.response.R;
import com.yf.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/sum")
public class ApiSumController {

    @Autowired
    private BusApplyService busApplyService;

    @Autowired
    private CostApplyService costApplyService;

    @Autowired
    private GoodsApplyService goodsApplyService;

    @Autowired
    private TodoService todoService;

    /**
     * 统计代办事项
     * 出差审核
     * 请假审核
     * 费用审核
     * 物料审核
     * 日程考核
     *
     * @return
     */
    @RequestMapping("/check")
    public R sumWait(@LoginUserId  Long userId){
        //请假
        Integer bus0 = busApplyService.sumCheck(userId,0);
        //出差
        Integer bus1 = applyService.sumCheck(userId);
        //费用
        Integer cost = costApplyService.sumCheck(userId);
        //物料申请
        Integer goods = goodsApplyService.sumCheck(userId);
        //日程审核
        Integer todo = todoService.sumCheck(userId);
        //晒单审核
        List<ImgOrderVo> orderEntities = imgOrderService.listByTop(userId);
        //有money的才需要审核 且未审核的
        orderEntities = orderEntities.stream().filter(imgOrderVo -> imgOrderVo.getImgOrder().getMoney().compareTo(BigDecimal.ZERO)>0&&imgOrderVo.getImgOrder().getStatus().equals(ImgOrderStatusEnum.WAIT.getIndex())).collect(Collectors.toList());
        Integer img = orderEntities.size();
        return R.ok().putExtra("bus0",bus0).putExtra("bus1",bus1).putExtra("cost",cost).putExtra("goods",goods).putExtra("todo",todo).putExtra("img",img);
    }

    @Autowired
    private ImgOrderService imgOrderService;

    @Autowired
    private ApplyService applyService;


}
